package org.heima.lib.future;

import org.heima.lib.HMFuture;

import com.lidroid.xutils.http.HttpHandler;
import com.lidroid.xutils.http.HttpHandler.State;

public class HttpFuture implements HMFuture {

	private HttpHandler handle;

	public HttpFuture(HttpHandler handle) {
		this.handle = handle;
	}

	@Override
	public boolean isCancelled() {
		return handle == null || handle.isCancelled();
	}

	@Override
	public boolean cancel(boolean mayInterruptIfRunning) {
		return handle == null || handle.cancel(mayInterruptIfRunning);
	}

	@Override
	public boolean isFinished() {
		if (handle == null) {
			return true;
		}

		State state = handle.getState();

		if (state == State.FAILURE || state == State.SUCCESS) {
			return true;
		}

		return false;
	}
}
